﻿-- ===============================================================================================
-- Empresa
-- ===============================================================================================

DECLARE @EnterpriseID AS BIGINT

SET @EnterpriseID = (SELECT Ent_ID FROM [esf_sso].[VEnterprise] WHERE Ent_Code = 'ESF')

-- ===============================================================================================
-- Usuarios
-- ===============================================================================================

DECLARE @AdminUserGroupID BIGINT
DECLARE @RootUserID BIGINT
DECLARE @PublicUserGroupID BIGINT


SET @RootUserID = (SELECT PersonID FROM [esf_sso].[User] WHERE [Alias] = 'root')


-- ===============================================================================================
-- User Menus para ESF.SSO.Admin
-- ===============================================================================================

IF NOT EXISTS (SELECT ID FROM esf_sso.VApplication WHERE Code = 'ESF.SSO.Admin')
BEGIN
	INSERT INTO [esf_sso].[BasicReference] ([BasicReferenceTypeID],[Code],[Name],[Description],[IsEnabled],[CreationDateTime], UserCreationAlias, Extra_I)
	SELECT 4, 'ESF.SSO.Admin', 'Admin. Menus, Usuarios', NULL, 1, GETDATE (),'root', '/sso/Admin/'
END


DECLARE @xID INT

DECLARE @path VARCHAR (MAX)


-- Reinsertar las referencias basicas
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, NULL, 'ESF.SSO.Admin_Inicio', 'Principal', NULL, '0', '/Cliente/Default.aspx'
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, NULL, 'ESF.SSO.Admin_Gen', 'General', NULL, '1', NULL

EXEC esf_sso.P_CreateAsignMenuBasicReferenceTypes 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Gen', 1, 29

EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, NULL, 'ESF.SSO.Admin_Usr', 'Usuarios', NULL, '2', NULL
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Usr', 'ESF.SSO.Admin_Usr_Browse', 'Directorio de Usuarios', NULL, NULL, 'User/BrowseUsers.aspx'
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Usr', 'ESF.SSO.Admin_Usr_BrowseEnterprises', 'Directorio de Empresas', NULL, NULL, 'Enterprise/BrowseEnterprises.aspx'
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Usr', 'ESF.SSO.Admin_Usr_ResponseContactUs', 'Responder Solicitudes', NULL, NULL, 'User/ResponseContactUs.aspx'
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Usr', 'ESF.SSO.Admin_Usr_SendMessage', 'Enviar Mensajes', NULL, NULL, 'User/SendMessage.aspx'

EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, NULL, 'ESF.SSO.Admin_Conf', 'Configuración', NULL, '3', NULL
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Conf', 'ESF.SSO.Admin_Conf_GenMenus', 'Editar Menu General', NULL, NULL, 'Menu/EditGeneralMenu.aspx'

EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Conf', 'ESF.SSO.Admin_Conf_UsrGrpMenus', 'Editar Menu por Grupo', NULL, NULL, 'Menu/EditUserGroupMenu.aspx'

EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, NULL, 'ESF.SSO.Admin_Rep', 'Reportes Admin', NULL, '4', NULL
SET @path = 'reports/Users/frmUserReports.aspx?ReportPath=' + CHAR (126) + '/Reports/Users/OPERATIONEXECUTIONSTATISTICS';
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Rep', 'ESF.SSO.Admin_Rep_GenMenus', 'Conteo de Operaciones', NULL, NULL, @path
SET @path = 'reports/Users/frmUserReports.aspx?ReportPath=' + CHAR (126) + '/Reports/Users/UserSessions'
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Rep', 'ESF.SSO.Admin_Rep_UsrGrpMenus', 'Sesiones de Usuario', NULL, NULL, @path
SET @path = 'reports/Users/frmUserReports.aspx?ReportPath=' + CHAR (126) + '/Reports/Users/UsersOnline'
EXEC [esf_sso].P_CreateAsignUserMenu @xID OUT, 'ESF.SSO.Admin', NULL, 'ESF.SSO.Admin_Rep', 'ESF.SSO.Admin_Rep_UploadTemp', 'Usuarios en Linea', NULL, NULL, @path
